package com.java.jvm;

import java.net.URL;
import java.net.URLClassLoader;

public class ClassLoaderClient {
	public static void main(String[] args) {
		//showClassLoaderPath();
		ctype();
	}

	public static void ctype(){
		Class cs = String.class;
		System.out.println(cs.getClassLoader());// null 由BootstrapClassloader加载
		System.out.println(ClassLoaderClient.class.getClassLoader());//sun.misc.Launcher$AppClassLoader@addbf1
	}

	@SuppressWarnings("restriction")
	public static void showClassLoaderPath() {
		System.out.println("BootstrapClassLoader: ");
		URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs();
		for(URL url : urls){
			System.out.println(url.getPath());
		}
		System.out.println("BootstrapClassloader的加载目录： " + System.getProperty("sun.boot.class.path"));
		System.out.println("----------------------------");
		URLClassLoader extClassLoader = (URLClassLoader)ClassLoader.getSystemClassLoader().getParent();
		System.out.println(extClassLoader.getClass().getName() + ": ");
		urls = extClassLoader.getURLs();
		for(URL url : urls) {
			System.out.println(url);
		}
		System.out.println("ExtClassloader的加载目录： " + System.getProperty("java.ext.dirs"));
		System.out.println("----------------------------");
		URLClassLoader appClassLoader = (URLClassLoader)ClassLoader.getSystemClassLoader();
		System.out.println(appClassLoader.getClass().getName() + ": ");
		urls = appClassLoader.getURLs();
		for(URL url : urls) {
			System.out.println(url);
		}
		System.out.println("AppClassloader的加载目录： " + System.getProperty("java.class.path"));
	}
}
